<?php

abstract class My_Controller_ActionAdmin extends My_Controller_Action {

    const ADMIN_LOGIN_PAGE_URL = '/admin123/sign/in';

    protected $layoutPath = '../modules/admin/layouts/scripts';
    protected $modalDisabled = false;
    protected $formRendered = false;

    public function saveLogs() {
        // admin module without logs
    }

    public function isAllowedAction($controllerName, $actionName) {
        if ($this->hasIdentity && $this->user['role'] == 'admin') {
            return true;
        }
        $this->addError($this->_('XXX_ADMIN_ADMIN_PERMISSION_REQUIRED'));
        return self::ADMIN_LOGIN_PAGE_URL;
    }

    public function init() {
        parent::init();
        $this->ajaxCheckPaymentStatusDisable = true;
        if ($this->layoutPath) {
            $this->layout->setLayoutPath(APPLICATION_PATH . '/' . $this->layoutPath);
        }
        $this->view->menuSelected = $this->_request->getControllerName();
        $this->view->submenuSelected = $this->_request->getActionName();
    }

    private static function _extractNthElement($str, $delimeter = '-', $elem = 0) {
        $t = explode($delimeter, $str);
        if (!empty($t) && isset($t[$elem])) {
            return $t[$elem];
        }
        return null;
    }

    public function setSubmenuDisabled($isDisabled = true) {
        $this->view->isSubmenuDisabled = $isDisabled;
    }

    public function renderForm() {
        $this->formRendered = true;
        if ($this->isAjax() && !$this->modalDisabled && isset($this->view->form)) {
            $this->renderScript('common/modal-form.phtml');
        } else {
            $this->renderScript('common/form.phtml');
        }
    }

    public function setModalDisabled($isDisabled = true) {
        $this->modalDisabled = $isDisabled;
    }

    public function url(array $routeParam, $route = 'admin', $clear = true) {
        return parent::url($routeParam, $route, $clear);
    }
    
    protected function getRightColumnContent() {
        return '';
    }

}
